package com.xjgc.ws.util;

import com.xjgc.common.config.DbConn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Component
public class CheckData {

	@Autowired
	DbConn db;

	public  String getUidByWekrs(String wekrs) { //工厂
		String uid = "";
		String sql = "select uid from zxj_uid_mapping where wekrs='" + wekrs + "'";
		ResultSet rs = null;
		PreparedStatement pst = null;

		try {
			pst = db.getConnetion().prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
					uid = rs.getString("uid");
				}
			pst.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			db.closeCn();
		}
		if(uid == null ||uid.equals("")) {
			uid = "0000";
		}
//		if("5501".equals(wekrs) || "5502".equals(wekrs) || "5601".equals(wekrs) ||"5901".equals(wekrs)) {//珠海许继公司
//			uid = "zhxj";
//		}else if("1201".equals(wekrs)) {//山东电子公司
//			uid = "sddz";
//		}else {
//			uid = "0000";
//		}
		return uid;
	}
	public String getUidByVkorg(String vkorg) {//销售组织
		String uid = "";
		
		String sql = "select uid from zxj_uid_mapping where vkorg='" + vkorg + "'";
		ResultSet rs = null;
		PreparedStatement pst = null;
		try {
			pst = db.getConnetion().prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
					uid = rs.getString("uid");
				}
			pst.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			db.closeCn();
		}
		if(uid == null ||uid.equals("")) {
			uid = "1111";
		}		
		
//		if("9255".equals(vkorg) || "9256".equals(vkorg) || "9259".equals(vkorg) ) {//珠海许继公司
//			uid = "zhxj";
//		}else if("9212".equals(vkorg)) {//山东电子公司
//			uid = "sddz";
//		}else {
//			uid="1111";
//		}
		return uid;
	}
}
